package chap06;

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

public class FritsGui {
    public static void main(String[] args) {
//        Swing();
//        Swing2();
//        Swing3();
//        Swing4();
//         Swing5();
//        Swing6();
//        JFrame();
//        JPanel();
//        JLabel();
//        Font();
//        ImageIcon();
//        JButtonDemo01();
//        JButtonDemo02();
//        JTextField();
            JMenu();










    }

    public static void Swing() {
        JFrame frame = new JFrame(" Swing 测试");
        JButton but = new JButton("按钮");
        JLabel lab = new JLabel("标签");
        frame.setLayout(new FlowLayout(FlowLayout.CENTER));
        frame.add(lab);
        frame.add(but);
        frame.setSize(2000, 1000);
//         Automatic length
        frame.pack();

        frame.setVisible(true);
    }

    public static void Swing2() {
        JFrame frame = new JFrame("achieve direction");
        frame.setLayout(new BorderLayout(20, 20));
        frame.add(new JButton("east"), BorderLayout.EAST);
        frame.add(new JButton("weat"), BorderLayout.WEST);
        frame.add(new JButton("south"), BorderLayout.SOUTH);
        frame.add(new JButton("north"), BorderLayout.NORTH);
        frame.add(new JButton("center"), BorderLayout.CENTER);

        frame.setSize(500, 300);
        //定位中心点
        frame.setLocation(400, 300);
        frame.setVisible(true);
    }

    //how to loop to loop input
    public static void Swing3() {
        JFrame frame = new JFrame("Loop to loop input ");
        frame.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 20));
        JButton button = null;
        for (int i = 0; i < 9; i++) {
            button = new JButton("Button-" + i);
            frame.add(button);
        }
//            frame.pack();
        frame.setSize(500, 300);
        frame.setLocation(400, 300);
        frame.setVisible(true);
    }

    public static void Swing4() {
        JFrame frame = new JFrame("GirdLayout");
        frame.setLayout(new GridLayout(3, 5, 3, 3));
        JButton button = null;
        for (int i = 0; i < 13; i++) {
            button = new JButton("Button-" + i);
            frame.add(button);
        }
        frame.setSize(500, 300);
        frame.setLocation(400, 300);
        frame.setVisible(true);
    }

    public static void Swing5() {
        //相叠在一起
        JFrame frame = new JFrame("CardLayout");
        CardLayout card = new CardLayout();//容器
        frame.setLayout(card);//装载容器
        Container con = frame.getContentPane();//装载到公共容器上
        con.add(new JLabel("标签-A", JLabel.CENTER), "Frist");
        con.add(new JLabel("标签-b", JLabel.CENTER), "Socend");
        con.add(new JLabel("标签-c", JLabel.CENTER), "Third");
        con.add(new JLabel("标签-d", JLabel.CENTER), "Fourth");
        con.add(new JLabel("标签-e", JLabel.CENTER), "Fifth");
        frame.pack();
        frame.setVisible(true);
        card.show(con, "third");
        for (int i = 0; i < 5; i++) {
            card.next(con);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void Swing6() {
        JFrame frame = new JFrame("absolute");
        frame.setLayout(null);//不要窗口？
        JLabel title = new JLabel("www.baidu.com");
        JButton enter = new JButton("enter");
        JButton help = new JButton("help");
        frame.setLocation(300, 200);
        frame.setBounds(45, 5, 150, 20);
        enter.setBounds(280, 30, 100, 80);
        help.setBounds(100, 50, 200, 100);
        frame.add(title);
        frame.add(enter);
        frame.add(help);
        frame.setSize(500, 400);
        frame.setVisible(true);
    }

    public static void JFrame() {
        JFrame jf = new JFrame("Just is  from");
        // Dimension = Size
        Dimension d = new Dimension(300, 200);
        jf.setSize(d);
        Point o = new Point(600, 400);
        jf.setLocation(o);
        jf.setVisible(true);
//        ???
        jf.setResizable(false);
    }
    public static void JPanel(){
        JFrame frame=new JFrame("show it ,JPanel");
        JPanel Panel=new JPanel();
        Panel.add(new JLabel("标签-1"));
        Panel.add(new JLabel("标签-2"));
        Panel.add(new JLabel("标签-3"));
        Panel.add(new JButton("标签-4"));
        Panel.add(new JButton("标签-5"));
        Panel.add(new JButton("标签-5"));
        frame.add(Panel);
        frame.pack();
        frame.setLocation(300, 200);
        frame.setVisible(true);
    }
    public static void JLabel(){
        JFrame frame = new JFrame("show it ,JLabel");
        JLabel lab = new JLabel("contnet", JLabel.CENTER);
        frame.add(lab);
        Dimension d = new Dimension(300, 200);
        frame.setSize(d);
        Point p = new Point(500, 400);
        frame.setLocation(p);
        frame.setVisible(true);
    }
    public static void Font(){
        JFrame frame = new JFrame("show it ,font");
        JLabel lab = new JLabel("contnet,and i will to show content");
        Font font = new Font("Dialog", Font.ITALIC+Font.BOLD, 30);
        lab.setFont(font);
        Dimension d = new Dimension(300, 200);
        Point p = new Point(500, 400);
        frame.setLocation(p);
        frame.setSize(d);
        frame.add(lab);
        frame.setVisible(true);
    }
    public static void ImageIcon(){
        JFrame frame = new JFrame("have pictrue");
        Icon icon = new ImageIcon("E:\\JAVA\\java_demo\\image\\photo.jpg");
        JLabel lab = new JLabel("KENDE", icon, JLabel.CENTER);
        Font font = new Font("Serif", Font.ITALIC + Font.BOLD, 30);
        lab.setFont(font);
        frame.add(lab);
        Dimension d = new Dimension(300, 200);
        frame.setSize(d);
        Point p = new Point(500, 400);
        frame.setLocation(p);
        frame.setVisible(true);
        //限制图片的像素 和高度
    }
    public static void JButtonDemo01(){
        JFrame frame = new JFrame("have Button");
        JButton bt = new JButton("按钮");
        frame.add(bt);
        frame.setSize(300, 200);
        frame.setLocation(300, 200);
        frame.setVisible(true);
    }
    public static void JButtonDemo02(){
        JFrame frame = new JFrame("have Button");
        String pickPath = "E:\\JAVA\\java_demo\\image\\photo.jpg";
        Icon icon = new ImageIcon(pickPath);
        JButton bt = new JButton(icon);
        frame.add(bt);
        frame.setSize(300, 200);
        frame.setLocation(300, 200);
        frame.setVisible(true);
    }

    public static void JTextField(){
        JFrame frame = new JFrame("test JTExtFiled");
//        JTextField jtf = new JTextField("Hello ?");
        JPasswordField jtf = new JPasswordField(10);
        jtf.getText();
        frame.add(jtf);
        frame.pack();
        frame.setVisible(true);
        //设置文本的水平对齐的方法
        jtf.setHorizontalAlignment(JTextField.CENTER);
    }
    public static void JMenu() {
        JFrame frame = new JFrame("测试");
        JMenuBar menuBar = new JMenuBar();
        JMenu fileMenu = new JMenu("文件");
        JMenu editMenu = new JMenu("编辑");
        JMenu helpMenu = new JMenu("帮助");
        menuBar.add(fileMenu);
        menuBar.add(editMenu);
        menuBar.add(helpMenu);
        JMenuItem newItem = new JMenuItem("新建");
        JMenuItem openItem = new JMenuItem("打开");
        JMenuItem exitItem = new JMenuItem("退出");
        fileMenu.add(newItem);
        fileMenu.add(openItem);
        fileMenu.add(exitItem);
        JMenuItem copyItem = new JMenuItem("复制");
        JMenuItem cutItem = new JMenuItem("剪切");
        JMenuItem pasteItem = new JMenuItem("粘贴");
        editMenu.add(copyItem);
        editMenu.add(cutItem);
        editMenu.add(pasteItem);
        frame.add(menuBar);
        JMenuItem helpItem = new JMenuItem("打开帮助文档");
        helpMenu.add(helpItem);
        frame.add(menuBar,"North");
//        frame.setJMenuBar(menuBar);
//        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setBounds(250, 200, 400, 300);
//        frame.addWindowListener(new MyWindowEventHandle2());
        frame.addWindowListener(new WindowAdapter() {
            public void windowActivated(WindowEvent e){
                System.out.println("11");
            }
        });

        frame.setVisible(true);
    }
    public static void s(){

    }


}
    class MyWindowEventHandle implements WindowListener{
    @Override
    public void windowActivated(WindowEvent e) {
        System.out.println("选中");
        }

    @Override
    public void windowClosing(WindowEvent e) {

    }

    @Override
    public void windowIconified(WindowEvent e) {

    }

    @Override
    public void windowOpened(WindowEvent e) {

    }

    @Override
    public void windowDeiconified(WindowEvent e) {

    }

    @Override
    public void windowClosed(WindowEvent e) {

    }

    @Override
    public void windowDeactivated(WindowEvent e) {

    }
}
class MyWindowEventHandle2 extends WindowAdapter {
    public void windowActivated(WindowEvent e) {
        System.out.println("SB了");

    }
}

